package com.facotry.service.Impl;

import com.facotry.entity.FacUser;
import com.facotry.entity.ProduceOrder;
import com.facotry.mapper.ProduceOrderMapper;
import com.facotry.service.ProduceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * ------ 天道酬勤 -------
 *
 * @author ChenZihao
 * @date 2024/7/23
 * @desc --- 代码敲烂 月薪过万 ---
 */

@Service
public class ProduceOrderServiceImpl implements ProduceOrderService {
    @Autowired
    private ProduceOrderMapper produceOrderMapper;

    @Override
    public List<ProduceOrder> findAll(HashMap<String, String> map) {

        List<ProduceOrder> list = produceOrderMapper.findAll(map);
        return list;
    }

    @Override
    public Object findProduct(long l) {
        Object o = produceOrderMapper.findProduct(l);
        return o;
    }

    @Override
    public boolean add(ProduceOrder produceOrder) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        System.out.println("request = " + request);
        FacUser info = (FacUser) request.getSession().getAttribute("userInfo");
        System.out.println("info = " + info);
        String username = info.getUsername();
        System.out.println("username = " + username);
        produceOrder.setCreater(username);
        produceOrder.setCreateTime(new Date());
        System.out.println("produceOrder = " + produceOrder);
        boolean isOk = produceOrderMapper.add(produceOrder);
        return isOk;
    }

    @Override
    public int delBatch(List<String> list) {
        int i = produceOrderMapper.delBatch(list);
        return i;
    }

    @Override
    public boolean delOrderByNum(String num) {
        boolean isOk = produceOrderMapper.delOrderByNum(num);
        return isOk;
    }

    @Override
    public boolean editOrder(ProduceOrder produceOrder) {
       boolean isOk =  produceOrderMapper.editOrder(produceOrder);
        return isOk;
    }
}
